import requests
from loguru import logger
from urllib3 import response
from basic.parser_files import read_file

from api.base import Login


class MerchantOrder(Login):
    # orderNo 订单号
    def order_list(self,dateLimit=None, orderNo=None):
        """订单查询"""
        data = {
            "method": "get",
            "url": "/api/admin/merchant/order/list",
            "headers": {'authori-zation': self.mer_token},
            "params": {
                'status': 'all',
                'dateLimit': 'dateLimit',
                'orderNo': 'orderNo',
                'page': '1',
                'limit': '20',
                'type': '',
                'searchType': 'all',
                'content': '',
                'temp': '1735896263',
            }
        }
        return self.send_mer_requests(data)

    def order_verification(self,verifyCode):
        """订单核销,verifyCode：核销码"""
        data = {
            "method": "post",
            "url": "/api/admin/merchant/order/verification",
            "headers": {"content-type":"application/json",'authori-zation': self.mer_token},
            "json": {"verifyCode":verifyCode}
        }
        return self.send_mer_requests(self.order_verification.__name__,data)

    def order_info(self,orderNo):
        """订单详情"""
        data = {
            "method": "get",
            "url": f"/api/admin/merchant/order/{orderNo}",
            "headers": {'authori-zation': self.mer_token},
        }
        return self.send_mer_requests(self.order_info.__name__,data)

    def order_mark(self,remark,orderNo):
        """订单备注，remark：备注内容"""
        data = {
            "method": "post",
            "url": "/api/admin/merchant/order/mark",
            "headers": {"content-type":"application/json",'authori-zation': self.mer_token},
            "json": {"remark":remark,"orderNo":orderNo}
        }
        return self.send_mer_requests(self.order_mark.__name__,data)
    def check_order(self):
        return read_file(self.mer_json_path + "/order_info.json")

    def order_printreceipt(self,orderNo):
        """打印小票"""
        data = {
            "method": "get",
            "url": f"/api/admin/merchant/order/printreceipt/{orderNo}",
            "headers": {"content-type":"application/json",'authori-zation': self.mer_token},
        }
        return self.send_mer_requests(self.order_printreceipt.__name__,data)

if __name__ == '__main__':
    obj = MerchantOrder()
    print(obj.check_order_info())
